/**
 * 提问
 * 
 * @param askToId
 * @param userName
 */	
function askTo(askToId, userName) {
	DianziQ.openWin({
		loadUrl:Constans.BASE_PATH+"dialogCode.jsp #askto",
		title:"向 " + userName + " 提问",
		afterFun:function(){
			$("#addQ_title").val($("#searchBox").val());
			$("#addQ_submit").click(function() {
				askToQuestion(askToId);// 向别人提问
			});
			// 没有用的自己隐藏掉
			$("#addQ_addTags").css("display", "none");
			$("#isnm").css("display", "none");
			$("#guest").css("display", "none");
			$("#addQ_cancel").bind("click",function() {
				$("#modal-dialog").css("display","none");// 没有用的自己隐藏掉
				$("#modal-dialog-content").find("textarea").val("");
				$("#modal-dialog-content").find("input").val("");
				$("#xvrw").css("display", "none");
				$("#xqq").removeClass("xxzd xer xd goog-zippy-expanded").addClass("xxzd xer xd goog-zippy-collapsed");
				$("#xuq").css("display", "none");
				$("#addQ_addTags").removeClass("xxzd xer xd goog-zippy-expanded").addClass("xxzd xer xd goog-zippy-collapsed");
			});

			$("#xqq").toggle(
				function() {
					$("#xvrw").css("display", "block");
					$("#xqq").removeClass("xxzd xer xd goog-zippy-collapsed").addClass("xxzd xer xd goog-zippy-expanded");
				},
				function() {
					$("#xvrw").css("display", "none");
					$("#xqq").removeClass("xxzd xer xd goog-zippy-expanded").addClass("xxzd xer xd goog-zippy-collapsed");
				}
			);

			$("#addQ_addTags").toggle(
					function() {
						$("#xuq").css("display", "block");
						$("#addQ_addTags").removeClass("xxzd xer xd goog-zippy-collapsed").addClass("xxzd xer xd goog-zippy-expanded");
					},
					function() {
						$("#xuq").css("display", "none");
						$("#addQ_addTags").removeClass("xxzd xer xd goog-zippy-expanded").addClass("xxzd xer xd goog-zippy-collapsed");
					}
			);
		}
	});
}
	

	//显示隐藏添加话题经验框
	function addExpEvent(){
		var cookid = $("#cookid").val();
		$("a[name='addTagExp']").bind("click",function(){
			if(DZQCheckForUser()){
				return;
			}
			$editBox = $(this).parent().siblings("div[name='editBox']").show();
			$(this).hide();
			var trigger = this;
			$editBox.find("textarea").val("");
			saveCancelEvent(trigger,$editBox);
		});		
		
		$("a[name='editTagExp']").bind("click",function(){
			if(DZQCheckForUser()){
				return;
			}
			$editBox = $(this).siblings("div[name='editBox']").show();
			$(this).siblings("div[name='detail']").hide();	
			$(this).hide();
			var trigger = this;
			saveCancelEvent(trigger,$editBox);
		});		


	}
	
	function saveCancelEvent(trigger,editBox){
		$editBox.find("a[name='save']").bind("click",function(){
			var data = $(this).attr("data-tag");
			data = data.split("-");
			var newval = $editBox.find("textarea").val();
			
			addtopicExperience(data[0],data[1],newval,$(this).parent().parent().next());
			$editBox.hide();
			$(trigger).show();
		});
		$editBox.find("a[name='cancel']").bind("click",function(){
			var data = $(this).attr("data-tag");
			$editBox.find("textarea").val(data);
			$editBox.hide();
			$(trigger).show();
			$(trigger).siblings("div[name='detail']").show();
		});
	}
	
	/**
	 * 添加话题经验
	 */
	function addtopicExperience(uid,tag,detail,$trigger) {
		//console.log($trigger.html());
		Wenda.post(basePath+"json/userJsonAction!updateTagExp.action", {
			"uid" : uid,
			"tag" : tag,
			"detail":detail
		
		}, function(data) {
			//$("#ask"+tag).html(detail);
			$trigger.html(detail);
			$(".addTagtopic").hide();
			if(null!= detail||detail!=""){	
				$trigger.show();
		}
		}, 'json');
	}
	
	

	/**
	 * 添加问题
	 */
	function askToQuestion(askTo) {
		if(isSubmit)return;
		var qtitle = $("#addQ_title").val();
		var qcontent = $("#wtbc").val();
		var domainId = 0;
		if(document.getElementById("currentdomainid")){
			domainId = document.getElementById("currentdomainid").value;
		}
		//var huati = $("#addQ_tags").val();
		var huati = $("#addQ_tags").val()+" ";
		var ta = $("#addQ_tagList").find("span");
		for(var i= 0;i < ta.length;i++){
			huati += $(ta[i]).text()+" ";
		}
		var isnm = $("#isnm").val();
		Wenda.post(basePath+"json/questionJsonAction!askQuestion.action", {
			"question.title" : qtitle,
			"question.content" : qcontent,
			"question.tag" : huati,
			"isAnonymous" : isnm,
			"domainId" : domainId,
			"question.askto" : askTo // askTo
		}, function(data) {
			if (data.isLogin == 'no') {
				window.location.href = basePath+"login.jsp";
				return;
			}
			if (data.messages != '') {
				//alert(data.messages);
				Wenda.alert(data.messages,"提示消息",{
					"确定" : function(){
						$(this).dialog("close");
					}
				});
				return;
			}
			var questionId = data.question.id;
			if (questionId > 0) {// 问题添加成功
				//alert("问题添加成功，问题ID为" + questionId);
				window.location.href = basePath+"question/question!fetchQuestion.action?qid="+questionId;
			}
		}, 'json');
	}

	
